<?php

namespace App\Http\Middleware;

use App\Models\MLog;
use App\Models\MUser;
use Closure;
use Illuminate\Support\Facades\Log;

class AuthLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $header_account= $request->header('account');

        if(!$header_account){
            return response()->json([
                'code' => -1,
                'message' => '账户不存在',
            ]);
        }
        $user =MUser::where('account',$header_account)->first();
        if(!$user){
            return response()->json([
                'code' => -1,
                'message' => '账户不正确',
            ]);
        }

//        if(!$header_token){
//            return response()->json([
//                'code' => -1,
//                'message' => 'token失效',
//            ]);
//        }
//        $user =MUser::where('token',$header_token)->first();
//        if(!$user){
//            return response()->json([
//                'code' => -1,
//                'message' => 'token失效',
//            ]);
//        }

        $request->user = $user;
        $request->account = $header_account;
        return   $next($request);
    }
}